//
//  WCNItemChooseView.m
//  WCN
//
//  Created by wsj2015 on 15/9/21.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNItemChooseView.h"
#import "Macros.h"
#import "MyUtil.h"

@implementation WCNItemChooseView
{
//    UIView *_indeView;
    NSInteger _index;
    CGFloat  _width;
}





// 38  5
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        _width =frame.size.width / 3;
        CGFloat h =frame.size.height -5*2 ;
        CGFloat w = 60  ;
        CGFloat y =0 ;
        CGFloat edgeSpace =60;
        CGFloat space = (frame.size.width - w * 3 - edgeSpace *2)/3;
        for (int i =0; i<3; i++) {
            NSString *imageName = [NSString stringWithFormat:@"iconHome_%d",i+1];
            UIButton *btn =[MyUtil createBtnFrame:CGRectMake(edgeSpace +(w + space)* i, y, w, h) title:nil target:self action:@selector(itemChoose:)];
            [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
            btn.tag =200 +i;
            
            [self addSubview:btn];
        }
        
    }
    
//    _indeView =[[UIView alloc]initWithFrame:CGRectMake(0, frame.size.height-1, frame.size.width /4, 1)];
//    _indeView.backgroundColor =kMainColor;
//    [self addSubview:_indeView];
    return self;
    
}
-(void)itemChoose:(UIButton *)btn
{
    UIButton *preBtn =(UIButton *)[self viewWithTag:_index +200];
    if (btn == preBtn) {
        return;
    }
    
    _index =btn.tag -200;

    
    if (self.clickBlock) {
        self.clickBlock(btn.tag -200);
        NSLog(@"%li",btn.tag -200);
    }
    
    
    
    
}
@end